﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DTD2013.Entities;
using DTD2013.Common;

namespace DTD2013.MainApp.UI
{
    public partial class guiWorkTemplate : XtraForm
    {
        #region Properties

        /// <summary>
        /// Gets or sets cong tac tam tinh
        /// </summary>
        public CongTac CongTacTamTinh { get; set; }

        #endregion

        #region Variable

        /// <summary>
        /// Danh sach cong tac tam tinh da co truoc do
        /// </summary>
        private List<CongTac> CongTacTamTinhList;

        #endregion

        public guiWorkTemplate()
        {
            InitializeComponent();
        }

        public guiWorkTemplate(List<CongTac> ctttList)
        {
            InitializeComponent();
            CongTacTamTinh = new CongTac();
            CongTacTamTinhList = new List<CongTac>();
            CongTacTamTinhList.AddRange(ctttList);
        }

        private void btnXemDSCVTT_Click(object sender, EventArgs e)
        {
            guiWorkTemplateList workTemplateList = new guiWorkTemplateList(CongTacTamTinhList);
            workTemplateList.ShowDialog();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            CongTacTamTinh.MaHieu = string.Format(Constant.GTT0, CongTacTamTinhList.Count + 1);
            CongTacTamTinh.TenCongViec = medTenCV.Text;
            CongTacTamTinh.DonVi = txtDonVi.Text;
            CongTacTamTinh.DGVL = Convert.ToDouble(txtDGVL.EditValue);
            CongTacTamTinh.DGNC = Convert.ToDouble(txtDGNC.EditValue);
            CongTacTamTinh.DGCM = Convert.ToDouble(txtDGCM.EditValue);
            if (CongTacTamTinh.DGVL > 0)
            {
                DinhMuc hp = new DinhMuc();
                hp.LoaiHaoPhi = WasteType.A.ToString();
                hp.MaVatLieu = string.Format("{0}{1}", CongTacTamTinh.MaHieu, WasteTypeShortcut.VL);
                hp.TenVatLieu = string.Format(Constant.GTTVL, CongTacTamTinh.TenCongViec);
                hp.DonVi = CongTacTamTinh.DonVi;
                hp.KhoiLuong = 1;
                hp.GiaThuc = CongTacTamTinh.DGVL.Value;
                hp.ThanhTien = hp.GiaThuc;
                CongTacTamTinh.HaoPhiCongViecs.Add(hp);
            }
            if (CongTacTamTinh.DGNC > 0)
            {
                DinhMuc hp = new DinhMuc();
                hp.LoaiHaoPhi = WasteType.E.ToString();
                hp.MaVatLieu = string.Format("{0}{1}", CongTacTamTinh.MaHieu, WasteTypeShortcut.NC);
                hp.TenVatLieu = string.Format(Constant.GTTNC, CongTacTamTinh.TenCongViec);
                hp.DonVi = CongTacTamTinh.DonVi;
                hp.KhoiLuong = 1;
                hp.GiaThuc = CongTacTamTinh.DGNC.Value;
                hp.ThanhTien = hp.GiaThuc;
                CongTacTamTinh.HaoPhiCongViecs.Add(hp);
            }
            if (CongTacTamTinh.DGCM > 0)
            {
                DinhMuc hp = new DinhMuc();
                hp.LoaiHaoPhi = WasteType.F.ToString();
                hp.MaVatLieu = string.Format("{0}{1}", CongTacTamTinh.MaHieu, WasteTypeShortcut.MA);
                hp.TenVatLieu = string.Format(Constant.GTTCM, CongTacTamTinh.TenCongViec);
                hp.DonVi = CongTacTamTinh.DonVi;
                hp.KhoiLuong = 1;
                hp.GiaThuc = CongTacTamTinh.DGCM.Value;
                hp.ThanhTien = hp.GiaThuc;
                CongTacTamTinh.HaoPhiCongViecs.Add(hp);
            }
            DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
